import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MessageNotificationPage extends StatefulWidget {
  const MessageNotificationPage({super.key});

  @override
  State<MessageNotificationPage> createState() => _MessageNotificationPageState();
}

class _MessageNotificationPageState extends State<MessageNotificationPage> {
  bool notification = false;
  bool voice = false;
  bool vibration = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BrnAppBar(title: '消息通知', backgroundColor: Colors.white),
        backgroundColor: const Color(0xFFF6F6F6),
        body: Column(
          children: [
            _buildItem(
                title: '接受新消息通知',
                value: notification,
                action: (value) {
                  notification = value;
                  setState(() {});
                }),
            _buildItem(title: '', value: true),
            _buildItem(
                title: '声音',
                value: voice,
                isShowLine: true,
                action: (value) {
                  voice = value;
                  setState(() {});
                }),
            _buildItem(
                title: '震动',
                value: vibration,
                action: (value) {
                  vibration = value;
                  setState(() {});
                }),
          ],
        ));
  }

  Widget _buildItem({required String title, required bool value, Function? action, bool isShowLine = false}) {
    return Container(
      color: title.isNotEmpty ? Colors.white : Colors.transparent,
      padding: const EdgeInsets.symmetric(horizontal: 15),
      child: title.isNotEmpty
          ? Column(
              children: [
                Container(
                  padding: const EdgeInsets.symmetric(vertical: 15),
                  child: Row(
                    children: [
                      Text(title.tr,
                          style: TextStyle(fontSize: 15.sp, color: Colors.black, fontWeight: FontWeight.w500)),
                      const Spacer(),
                      BrnSwitchButton(
                        value: value,
                        onChanged: (value) {
                          action?.call(value);
                        },
                      )
                    ],
                  ),
                ),
                if (isShowLine) const Divider(color: Color(0xFFEEEEEE), height: 0.5, indent: 15, endIndent: 15)
              ],
            )
          : const SizedBox(height: 10),
    );
  }
}
